package ai4games_tests.soccer;

import game2dai.World;
import game2dai.entities.BaseEntity;
import game2dai.fsm.State;
import game2dai.fsm.Telegram;

public class TeamAttacking extends State implements Constants {


	private static TeamAttacking instance = null;
	
	public static TeamAttacking state(){
		if(instance == null){
			instance = new TeamAttacking();
			instance.name = "Attacking";
		}
		return instance;
	}
	
	@Override
	public void enter(BaseEntity owner) {
		Team team = (Team) owner;
		team.changePlayerHomePositions(ATTACKING);
		PlayerBase[] players = team.players;
		for(int i = 1; i < players.length; i++){
			if(players[i].FSM().isCurrentState(PlayerWait.state()))
					players[i].FSM().changeState(PlayerReturnToRegion.state());			
		}
	}

	@Override
	public void execute(BaseEntity owner, double deltaTime, World world) {
		Team team = (Team) owner;
		if(!team.isInControl())
			team.FSM().changeState(TeamDefending.state());
	}

	@Override
	public void exit(BaseEntity owner) {
	}

	@Override
	public boolean onMessage(BaseEntity owner, Telegram tgram) {
		return false;
	}

}
